package ai.zixing.service;

import ai.zixing.strategy.APlanStrategy;
import ai.zixing.strategy.PlanStrategyContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PlanService {

    /**
     * 策略上下文
     */
    @Resource
    private PlanStrategyContext context;

    /**
     * 业务方法
     * 首先更加上下文中获取到具体的实现策略，然后根据获取到的具体策略调用业务方法
     */
    public void explain() {
        // 获取到具体的实现策略
        APlanStrategy oneStrategy = context.getOneStrategy();
        System.out.println(oneStrategy.getStrategyName());
        String query = oneStrategy.queryPlan();
        oneStrategy.createPlan();
        System.out.println("query plan ====== " + query);
        String handlerPlan = oneStrategy.handlerPlan();
        System.out.println("handler plan ====== " + handlerPlan);
    }
}
